package com.prs.crm.service.assets.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.prs.crm.dao.assets.AssetsRevertDao;
import com.prs.crm.domain.assets.AssetsLiuXiang;
import com.prs.crm.domain.assets.AssetsRegister;
import com.prs.crm.domain.assets.AssetsRevert;
import com.prs.crm.domain.assets.RevertHistory;
import com.prs.crm.service.assets.AssetsLiuXiangService;
import com.prs.crm.service.assets.AssetsRevertService;
import com.prs.crm.service.assets.RevertHistoryService;
import com.prs.crm.service.impl.BaseServiceImpl;

public class AssetsRevertServiceImpl extends BaseServiceImpl<AssetsRevert, AssetsRevertDao>
					implements AssetsRevertService{
	private RevertHistoryService revertHistoryService;
	private RevertHistory rh;
	private Set<AssetsRegister> regs;
	private AssetsLiuXiangService assetsLiuXiangService;
	public AssetsLiuXiangService getAssetsLiuXiangService() {
		return assetsLiuXiangService;
	}

	public void setAssetsLiuXiangService(AssetsLiuXiangService assetsLiuXiangService) {
		this.assetsLiuXiangService = assetsLiuXiangService;
	}

	public Set<AssetsRegister> getRegs() {
		return regs;
	}

	public void setRegs(Set<AssetsRegister> regs) {
		this.regs = regs;
	}

	public RevertHistoryService getRevertHistoryService() {
		return revertHistoryService;
	}

	public void setRevertHistoryService(RevertHistoryService revertHistoryService) {
		this.revertHistoryService = revertHistoryService;
	}

	public RevertHistory getRh() {
		return rh;
	}

	public void setRh(RevertHistory rh) {
		this.rh = rh;
	}

	@Override
	public void saveRevertAndHistory(AssetsRevert re) {
		this.save(re);
		rh = new RevertHistory();
		rh.setId(re.getId());
		rh.setSname(re.getSname());
		rh.setSstate(re.getSstate());
		rh.setNumber(re.getNumber());
		rh.setUser(re.getUser());
		rh.setDept(re.getDept());
		rh.setDate(re.getDate());
		rh.setPerson(re.getPerson());
		if(re.getAssetsRegisters().size() != 0 || re.getAssetsRegisters() != null){
			regs = new HashSet<AssetsRegister>();
			for(AssetsRegister reg : re.getAssetsRegisters()){
				regs.add(reg);
			}
			rh.setAssetsRegisters(regs);
		}
		rh.setType(re.getType());
		rh.setSpr(re.getSpr());
		rh.setSplc(re.getSplc());
		rh.setRemark(re.getRemark());
		rh.setShuoming(re.getShuoming());
		this.revertHistoryService.save(rh);
	
//		AssetsLiuXiang assetsLiuXiang=new AssetsLiuXiang();
//		assetsLiuXiang.setId(re.getId());
//		assetsLiuXiang.setType("归还");
//		assetsLiuXiang.setLdep(re.getDept());
//		assetsLiuXiang.setLuser(re.getUser());
//		assetsLiuXiang.setPerson(re.getPerson());
//		assetsLiuXiang.setDate(re.getDate());
//		if (re.getAssetsRegisters().size()!=0||re.getAssetsRegisters()!=null) {
//			Set<AssetsRegister> assets=new HashSet<AssetsRegister>();
//			for (AssetsRegister asset : re.getAssetsRegisters()) {
//				assets.add(asset);
//			}
//			assetsLiuXiang.setAssetsRegisters(assets);
//		}
//		this.assetsLiuXiangService.save(assetsLiuXiang);
	}

	@Override
	public List<AssetsRevert> getAllAssetsRevert() {
		return this.getDao().getAllAssetsRevert();
	}
}
